package com.company.threads;

/**
 * @author xiaohutu
 * @Description: ${说明}
 * @date 2021/1/15 14:53
 */
public class MyWaitNotify {
    MonitorObject monitorObject = new MonitorObject();
    boolean wasSignalled = false;

    public void doWait() {
        synchronized (monitorObject) {
            if (!wasSignalled) {
                try {
                    monitorObject.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            wasSignalled = false;

        }
    }

    public void doNotify() {
        synchronized (monitorObject) {
            wasSignalled = true;
            monitorObject.notify();
        }
    }
}
